package com.example.targetOffer.controller;

import com.example.targetOffer.domain.CQueue;
import com.example.targetOffer.service.StackWithQueueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 剑指Offer: 栈与队列
 */
@RestController
@RequestMapping(value = "/StackWithQueue")
public class StackWithQueueController {

    @Autowired
    private StackWithQueueService stackTFQueueService;

    /**
     * 用两个栈实现队列（主要考察栈与队列的特性）
     * https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/
     */
    @RequestMapping(value = "StackTFQueue", method = RequestMethod.GET)
    public void StackTFQueue() {
        CQueue queue = new CQueue();
        for (int i = 1; i < 6; i++) {
            stackTFQueueService.appendTail(queue, i);
        }

        for (int j = 1; j < 6; j++) {
            stackTFQueueService.delHead(queue);
        }
    }

    /**
     * 获取栈中最小元素（构建辅助栈，以空间换时间的典型案例）
     * https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/
     */
    @RequestMapping(value = "MiniStack", method = RequestMethod.GET)
    public void MiniStack() {
        stackTFQueueService.minStack();
    }
}
